﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BusinessComponents;
using BusinessComponents.Managers;

namespace WaterfrontLodge.WebForms.RoomMgt
{
    public partial class RoomAdd : System.Web.UI.Page
    {
        #region Declaration
        IRoomMgr roomMgr = ManagerFactory.RoomMgr;
        IRoomTypeMgr typeMgr = ManagerFactory.RoomTypeMgr;
        #endregion
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                IEnumerable<RoomType> typeList = typeMgr.FindAllRoomTypes();
                ddlRoomType.DataSource = typeList;
                ddlRoomType.DataTextField = "Description";
                ddlRoomType.DataValueField = "TypeCode";
                ddlRoomType.DataBind();
            }

        }

        protected void btnCreate_Click(object sender, EventArgs e)
        {
            Room localRoom = roomMgr.GetRoom(txtRoomNo.Text);
            if (localRoom != null)
            {
                lblMessage.Text = "A similar room number found.";
            }
            else
            {
                localRoom = new Room();
                localRoom.RoomNo = txtRoomNo.Text;
                localRoom.TypeCode = Convert.ToInt16(ddlRoomType.SelectedItem.Value);
                localRoom.Remarks = txtRemarks.Text;
                localRoom.Status = Convert.ToInt16(rdbStatus.SelectedItem.Value);
                localRoom.CreatedDateTime = DateTime.Now;
                roomMgr.AddRoom(localRoom);
                roomMgr.Save();
                lblMessage.Text = "New Room added successfully!";
                Response.Redirect("~/WebForms/Room/RoomView.aspx");
            }
        }

        protected void ddlRoomType_SelectedIndexChanged(object sender, EventArgs e)
        {
            lblMessage.Text = ddlRoomType.SelectedValue;
        }

        protected void ddlRoomType_DataBinding(object sender, EventArgs e)
        {

        }

        protected void btnCancel_Click(object sender, EventArgs e)
        {
            Response.Redirect("~/WebForms/Room/RoomView.aspx");
        }
    }
}